package com.siqi.hr.system.organization.entity;

import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 部门对象实体
 * @author    xiaogq
 */
public class Dept {
	private static final long serialVersionUID = -3467779959470591319L;

	public Dept() {
	}

	public Dept(Long id) {
		this.id = id;
	}

	public Dept(Long id, String name) {
		this.id = id;
		this.name = name;
	}

	/**
	 * 部门id
	 */
	private Long id;

	/**
	 * 部门名称
	 */
	private String name;

	/**
	 * 创建时间
	 */
	private Date createDate;

	/**
	 * 更新时间
	 */
	private Date updateDate;

	/**
	 * 父级部门
	 */
	private Dept parent;

	/**
	 * 部门等级编号
	 */
	private String deptRank;

    /**
	 * 编制人数
	 */
	private Integer plaitPeople;

	/**
	 * 停用标记
	 */
	private boolean flag;

	/**
	 * 部门所在地址
	 */
	private String deptAddress;

	/**
	 * 是否是父级组织(0:否，1：是)
	 */
	private Boolean isParent;

	/**
	 * 图标地址
	 */
	private String icon;

	/**
	 * 描述
	 */
	private String description;

	/**
	 * 部门排序

	 */
	private int orderNum;

	/**
	 * 部门主管id列表,逗号分隔
     */
	private List<String> managerIdList;

	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Date getCreateDate() {
		return this.createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	public Date getUpdateDate() {
		return this.updateDate;
	}

	public void setUpdateDate(Date updateDate) {
		this.updateDate = updateDate;
	}

	public String getDeptAddress() {
		return this.deptAddress;
	}

	public void setDeptAddress(String deptAddress) {
		this.deptAddress = deptAddress;
	}

	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Dept getParent() {
		return this.parent;
	}

	public void setParent(Dept parent) {
		this.parent = parent;
	}

	public boolean isFlag() {
		return this.flag;
	}

	public void setFlag(boolean flag) {
		this.flag = flag;
	}

	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public Boolean getIsParent() {
		return isParent;
	}

	public void setIsParent(Boolean parent) {
		isParent = parent;
	}

	public Integer getPlaitPeople() {
		return plaitPeople;
	}

	public void setPlaitPeople(Integer plaitPeople) {
		this.plaitPeople = plaitPeople;
	}

	public String getDeptRank() {
		return deptRank;
	}

	public void setDeptRank(String deptRank) {
		this.deptRank = deptRank;
	}

	public int getOrderNum() {
		return orderNum;
	}

	public void setOrderNum(int orderNum) {
		this.orderNum = orderNum;
	}

	public List<String> getManagerIdList() {
		return managerIdList;
	}

	public void setManagerIdList(List<String> managerIdList) {
		this.managerIdList = managerIdList;
	}

	//查询部门所有字段信息
	public static class FullRecord extends Dept implements RowMapper<Dept> {
		public synchronized Dept mapRow(ResultSet rs, int index) throws SQLException {
			Dept dept = new Dept();
			dept.setId(rs.getLong("id"));
			dept.setName(rs.getString("name_varchar"));
			dept.setCreateDate(rs.getDate("create_date_datetime"));
			dept.setUpdateDate(rs.getDate("update_date_timestamp"));
			dept.setParent(new Dept(rs.getLong("pk_t_2_1")));
			dept.setPlaitPeople(rs.getInt("plait_people_decimal"));
			dept.setFlag(rs.getBoolean("flag_bit"));
			dept.setDeptAddress(rs.getString("dept_address_varchar"));
			dept.setIsParent(rs.getBoolean("isparent_bit"));
			dept.setDeptRank(rs.getString("dept_rank_varchar"));
			dept.setIcon(rs.getString("icon_varchar"));
			dept.setDescription(rs.getString("dept_description_textarea"));
			String managerIdStrs = rs.getString("manager_id_list_varchar") == null? "":rs.getString("manager_id_list_varchar");
			List<String> managerIds = Arrays.asList(managerIdStrs.replace("[","").replace("]","").replaceAll(" ","").trim().split(","));
			dept.setManagerIdList(managerIds);
			return dept;
		}
	}

	//查询部门所有字段以及父级部门信息
	public static class FullRecord2 extends Dept implements RowMapper<Dept> {
		public synchronized Dept mapRow(ResultSet rs, int index) throws SQLException {
			Dept dept = new Dept();
			dept.setId(rs.getLong("id"));
			dept.setName(rs.getString("name_varchar"));
			dept.setCreateDate(rs.getDate("create_date_datetime"));
			dept.setUpdateDate(rs.getDate("update_date_timestamp"));
			dept.setParent(new Dept(rs.getLong("pk_t_2_1"),rs.getString("parentName")));
			dept.setPlaitPeople(rs.getInt("plait_people_decimal"));
			dept.setFlag(rs.getBoolean("flag_bit"));
			dept.setDeptAddress(rs.getString("dept_address_varchar"));
			dept.setIsParent(rs.getBoolean("isparent_bit"));
			dept.setDeptRank(rs.getString("dept_rank_varchar"));
			dept.setIcon(rs.getString("icon_varchar"));
			dept.setDescription(rs.getString("dept_description_textarea"));
			String managerIdStrs = rs.getString("manager_id_list_varchar") == null? "":rs.getString("manager_id_list_varchar");
			List<String> managerIds = Arrays.asList(managerIdStrs.replace("[","").replace("]","").replaceAll(" ","").trim().split(","));
			dept.setManagerIdList(managerIds);
			return dept;
		}
	}

	//查询所有一级部门id跟名称字段信息
	public static class rootAllDept extends Dept implements RowMapper<Dept> {
		public synchronized Dept mapRow(ResultSet rs, int index) throws SQLException {
			Dept dept = new Dept();
			dept.setId(rs.getLong("id"));
			dept.setName(rs.getString("name_varchar"));
			dept.setDeptRank(rs.getString("dept_rank_varchar"));
			return dept;
		}
	}

}
